import Vue from 'vue'
import Router from 'vue-router'
import home from '@/views/home'
import login from '@/views/login'
import add from '@/views/add'

Vue.use(Router)

let router = new Router({
  routes: [
        {
            path:'/',
            redirect:'/home'
        },
        {
            path: '/home',
            name: 'home',
            component: home
        },
        {
            path:'/login',
            name:'login',
            component:login
        },
        {
            path:'/add',
            name:'add',
            component:add
        }
  ]
})

let routerArr = ['home'];

router.beforeEach((to,from,next) => {
    if(routerArr.indexOf(to.name) != -1){
        if(localStorage.getItem('uid')){
            next()
        }else{
            next('/login')
        }
    }else{
        next()
    }
})

export default router




